<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">




<meta http-equiv="x-ua-compatible" content="ie=7">
<title>[Spring.NET IoC] 之五：列表参数 - 豆豆网</title>
<meta name="keywords" content="Spring.NET IoC">


<link rel="stylesheet" type="text/css" href="index.css" media="all">
</head>
<body>
<div id="main">
	<div id="header">
		<div class="nav_top">
		<div class="nav_top_left">
<a style="background: transparent url(index_bg.gif) no-repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; margin-left: 6px; padding-left: 14px;" href="http://tech.ddvip.com/">首页</a>-<a href="http://tech.ddvip.com/os/index.html">系统</a>-<a href="http://tech.ddvip.com/safe/index.html"><strong>安全</strong></a>-<a href="http://tech.ddvip.com/program/index.html">编程</a>-<a href="http://tech.ddvip.com/db/index.html">数据库</a>-<a href="http://tech.ddvip.com/design/index.html">设计</a>-<a href="http://tech.ddvip.com/network/index.html"><strong>网络</strong></a>-<a href="http://tech.ddvip.com/comm/index.html">通信</a>-<a href="http://tech.ddvip.com/cert/index.html">认证</a>-<a href="http://tech.ddvip.com/office/index.html"><strong>办公</strong></a>-<a href="http://tech.ddvip.com/server/index.html">服务器</a>-<a href="http://tech.ddvip.com/ent/index.html">企业</a>-<a href="http://tech.ddvip.com/soft/index.html">软件</a>-<a href="http://tech.ddvip.com/machine/index.html">电子</a>
		  </div>
			<div class="search">
			     <form action="http://tech.ddvip.com/search.php" method="get" name="form1" target="_blank" id="form1">
      <input value="" name="key" id="key" size="24" maxlength="12" type="text">
	  <input class="button1" value="搜索" type="submit">
	</form>
			</div>
		</div>
	</div>
	<div class="tl" id="tl"><a href="http://www.killtest.cn/" target="_top"><img src="itrenzheng468x60.gif" border="0px" height="60px" width="468px"></a><a href="http://www.enkj.com/"><img src="enkj46860.gif" border="0" height="60" width="468"></a><a href="http://www.qiwan.net/"><img src="qiwan46860.gif" border="0" height="60" width="468"></a><a href="http://www.72e.net/?cid=ad_ddvip" target="_top"><img src="72e468x60.gif" border="0" height="60" width="468"></a></div>
	<div id="content">
    <div class="location">
	    <a href="http://www.ddvip.com/" target="_balnk">豆豆网</a>
    
        &gt; <a href="http://tech.ddvip.com/index.html">技术应用</a>
      
        &gt; <a href="http://tech.ddvip.com/program/index.html">编程</a>
      
        &gt; <a href="http://tech.ddvip.com/web/asp.net/index.html">ASP/.Net/ASP.NET</a>
      
	</div>
		<div class="left">
			<h1>[Spring.NET IoC] 之五：列表参数</h1>
			<div class="info"><a href="http://tech.ddvip.com/">http://tech.ddvip.com</a> &nbsp;&nbsp; 2009年10月15日 &nbsp;&nbsp; 来源：rainsts.net &nbsp;&nbsp; 作者：yuhen  &nbsp;&nbsp; <a href="javascript:window.external.AddFavorite(this.location.href,%20this.document.title)"><font color="#d90000">收藏本文</font></a>			</div>
			
			
		    <p style="border-bottom: 2px solid rgb(204, 204, 204); margin: 0pt 30px;"></p>
		    
			
					<div class="article_content">
					<div class="content_250x250">
<ins style="border: medium none ; margin: 0pt; padding: 0pt; display: inline-table; height: 280px; position: relative; visibility: visible; width: 336px;"><ins style="border: medium none ; margin: 0pt; padding: 0pt; display: block; height: 280px; position: relative; visibility: visible; width: 336px;"><iframe allowtransparency="true" hspace="0" id="google_ads_frame1" marginheight="0" marginwidth="0" name="google_ads_frame" src="index_1.html" style="left: 0pt; position: absolute; top: 0pt;" vspace="0" scrolling="no" frameborder="0" height="280" width="336"></iframe></ins></ins>

					</div>
					
          
	  <p>　　我们可以在配置文件中向构造方法或者属性注入列表型参数，诸如 Array、ArrayList、Hashtable 等。</p><p>　　1. IList</p><p>　　在 .NET Framework 中实现 IList 的主要是 Array、ArrayList。</p><p><code>&lt;?xml　version="1.0"　encoding="utf-8"?&gt;<br><span>&lt;objects　xmlns="<a href="http://www.springframework.net/" class="smarterwiki-linkify">http://www.springframework.net</a>"　xmlns:xsi="<a href="http://www.w3.org/2001/XMLSchema-instance" class="smarterwiki-linkify">http://www.w3.org/2001/XMLSchema-instance</a>"　</span><br><span>　　　　　　　　　xsi:schemaLocation="<a href="http://www.springframework.net/" class="smarterwiki-linkify">http://www.springframework.net</a>　</span><br><span>　　　　　　　　　<a href="http://www.springframework.net/xsd/spring-objects.xsd" class="smarterwiki-linkify">http://www.springframework.net/xsd/spring-objects.xsd</a>"&gt;</span><br>　　&lt;object　id="HelloWorld"　type="ConsoleApplication1.SpringNet.HelloWorld,　Learn.CUI"&gt;<br>　　　　&lt;constructor-arg　name="list"&gt;<br>　　　　　　&lt;list&gt;<br>　　　　　　　　&lt;value&gt;1&lt;/value&gt;<br>　　　　　　　　&lt;value&gt;2&lt;/value&gt;<br>　　　　　　　　&lt;value&gt;3&lt;/value&gt;<br>　　　　　　　　&lt;value&gt;4&lt;/value&gt;<br>　　　　　　&lt;/list&gt;<br>　　　　&lt;/constructor-arg&gt;<br>　　&lt;/object&gt;<br>&lt;/objects&gt;<br>public　class　HelloWorld<br>{<br>　　public　HelloWorld(IList　list)<br>　　{<br>　　　　Console.WriteLine(list);　//　output:　ArrayList<br>　　　　foreach　(object　o　in　list)<br>　　　　　　Console.WriteLine(o);<br>　　}<br>}</code></p><p>　　我们会发现 Spring.NET IoC 缺省使用 ArrayList 来实现 IList 列表参数。</p><p>　　2. IDictionary</p><p>　　实现 IDictionary 的最常用类型是 Hashtable。</p><p><code>&lt;?xml　version="1.0"　encoding="utf-8"?&gt;<br><span>&lt;objects　xmlns="<a href="http://www.springframework.net/" class="smarterwiki-linkify">http://www.springframework.net</a>"　xmlns:xsi="<a href="http://www.w3.org/2001/XMLSchema-instance" class="smarterwiki-linkify">http://www.w3.org/2001/XMLSchema-instance</a>"　</span><br><span>　　　　　　　　　xsi:schemaLocation="<a href="http://www.springframework.net/" class="smarterwiki-linkify">http://www.springframework.net</a>　</span><br><span>　　　　　　　　　<a href="http://www.springframework.net/xsd/spring-objects.xsd" class="smarterwiki-linkify">http://www.springframework.net/xsd/spring-objects.xsd</a>"&gt;</span><br>　　&lt;object　id="HelloWorld"　type="ConsoleApplication1.SpringNet.HelloWorld,　Learn.CUI"&gt;<br>　　　　&lt;constructor-arg　name="dict"&gt;<br>　　　　　　&lt;dictionary&gt;<br>　　　　　　　　&lt;entry　key="1"　value="a"　/&gt;<br>　　　　　　　　&lt;entry　key="2"　value="b"　/&gt;<br>　　　　　　　　&lt;entry　key="3"　value="c"　/&gt;<br>　　　　　　　　&lt;entry　key="4"　value="d"　/&gt;<br>　　　　　　&lt;/dictionary&gt;<br>　　　　&lt;/constructor-arg&gt;<br>　　&lt;/object&gt;<br>&lt;/objects&gt;<br>public　class　HelloWorld<br>{<br>　　public　HelloWorld(IDictionary　dict)<br>　　{<br>　　　　Console.WriteLine(dict);　//　output:System.Collections.Specialized.HybridDictionary<br>　　　　foreach　(object　o　in　dict.Keys)<br>　　　　{<br>　　　　　　Console.WriteLine("{0}={1}",　o,　dict[o]);<br>　　　　}<br>　　}<br>}</code></p><p>　　看看 System.Collections.Specialized.HybridDictionary 的MSDN说明</p><p>　　在集合较小时，使用 ListDictionary 来实现 IDictionary，然后当集合变大时，切换到 Hashtable。 </p><p>　　建议将该类用于字典中的元素数量未知的情况。它利用了 ListDictionary 处理小集合时性能改善的优点，同时也可灵活地切换到处理较大集合时能力比 ListDictionary 更好的 Hashtable。</p><p>　　如果集合的初始大小大于 ListDictionary 的最佳大小，那么集合立即存储在 Hashtable 中，以避免将元素从 ListDictionary 复制到 Hashtable 产生的系统开销。</p>
	  
			<div class="xg_list">
				<p>编缉推荐阅读以下文章</p>
				<ul>
	  
		      <li><a href="http://tech.ddvip.com/2009-10/1255600006135611.html">[Spring.NET IoC] 之四：配置补充</a></li>
		    
		      <li><a href="http://tech.ddvip.com/2009-10/1255599953135610.html">[Spring.NET IoC] 之三：获取对象</a></li>
		    
		      <li><a href="http://tech.ddvip.com/2009-10/1255599868135609.html">[Spring.NET IoC] 之二：配置文件</a></li>
		    
		      <li><a href="http://tech.ddvip.com/2009-10/1255599821135607.html">[Spring.NET IoC] 之一：基本信息</a></li>
		    
				</ul>
			</div>
			
	 <!-- 分页 -->
	 
	 <!-- 分页end -->
<div class="ad_google">

<ins style="border: medium none ; margin: 0pt; padding: 0pt; display: inline-table; height: 60px; position: relative; visibility: visible; width: 468px;"><ins style="border: medium none ; margin: 0pt; padding: 0pt; display: block; height: 60px; position: relative; visibility: visible; width: 468px;"><iframe allowtransparency="true" hspace="0" id="google_ads_frame2" marginheight="0" marginwidth="0" name="google_ads_frame" src="index_2.html" style="left: 0pt; position: absolute; top: 0pt;" vspace="0" scrolling="no" frameborder="0" height="60" width="468"></iframe></ins></ins>

</div>
					</div>
			<div class="new_list">
				<p><strong><a href="http://tech.ddvip.com/scroll/index.html">最近更新</a></strong>最后刷新时间：<em>2009-10-15 17:59:17</em></p>
				<ul>
	    
		      <li><a href="http://tech.ddvip.com/2009-10/1255600501135615.html">[Castle AR] 1. Starter</a></li>
		    
		      <li><a href="http://tech.ddvip.com/2009-10/1255600006135611.html">[Spring.NET IoC] 之四：配置补充</a></li>
		    
		      <li><a href="http://tech.ddvip.com/2009-10/1255599953135610.html">[Spring.NET IoC] 之三：获取对象</a></li>
		    
		      <li><a href="http://tech.ddvip.com/2009-10/1255599868135609.html">[Spring.NET IoC] 之二：配置文件</a></li>
		    
		      <li><a href="http://tech.ddvip.com/2009-10/1255599821135607.html">[Spring.NET IoC] 之一：基本信息</a></li>
		    
		      <li><a href="http://tech.ddvip.com/2009-10/1255599727135606.html">Castle.Windsor 类型和对象构造参数注入</a></li>
		    
		      <li><a href="http://tech.ddvip.com/2009-10/1255599619135605.html">[ActiveRecord] 之八：Queries</a></li>
		    
		      <li><a href="http://tech.ddvip.com/2009-10/1255599524135604.html">[ActiveRecord] 之七：多数据库配置</a></li>
		    
		      <li><a href="http://tech.ddvip.com/2009-10/1255599439135603.html">[ActiveRecord] 之六：继承</a></li>
		    
		      <li><a href="http://tech.ddvip.com/2009-10/1255599081135601.html">[ActiveRecord] 之五：ActiveRecordMediator</a></li>
		    
				</ul>
			</div>
		</div><!-- left -->
		<div class="right">
		<a href="http://news.ddvip.com/" target="_top"><img src="news_250x250.gif" border="0"></a>

									<div class="dep_right_c" style="margin: 0pt;">		
			<p><strong>精彩推荐</strong></p>
		<ul>
	  <li>·<a href="http://tech.ddvip.com/2009-06/1245052728123855.html" target="_top">综合应用WPF/WCF/WF/LINQ之一</a></li>
	  <li>·<a href="http://tech.ddvip.com/2009-06/1244428046122685.html" target="_top">【自然框架】之通用权限（一）</a></li>
	  <li>·<a href="http://tech.ddvip.com/2009-06/1243843736121827.html" target="_top">图解ASP.NET网站开发实战</a></li>
	  <li>·<a href="http://tech.ddvip.com/2009-05/1243651913121589.html" target="_top">.Net Framework源代码中的模式</a></li>
	  <li>·<a href="http://tech.ddvip.com/2009-05/1243648759121578.html" target="_top">lua学习之入门(一)----环境搭建</a></li>
	  <li>·<a href="http://tech.ddvip.com/2009-05/1243594529121515.html" target="_top">基于.NET平台的Windows编程实战</a></li>
	  <li>·<a href="http://tech.ddvip.com/2009-05/1242371543119288.html" target="_top">.net和CLR 4.0垃圾回收所做的改进</a></li>
	  <li>·<a href="http://tech.ddvip.com/2009-05/1241596073117947.html" target="_top">.NET CIL系列第一篇：介绍和入门</a></li>
	  <li>·<a href="http://tech.ddvip.com/2009-04/1240661104116857.html" target="_top">GDI+中常见的几个问题</a></li>
	  <li>·<a href="http://tech.ddvip.com/2009-04/1240039343115756.html" target="_top">ASP基础教程：ASP简介</a></li>
	  <li>·<a href="http://tech.ddvip.com/2009-04/1239454863114631.html" target="_top">Entity Data Model (EDM) 分析</a></li>
	  <li>·<a href="http://tech.ddvip.com/2009-04/1239453296114621.html" target="_top">MVC 1.0创建NerdDinner 范例程序</a></li>
	  <li>·<a href="http://tech.ddvip.com/2009-04/1239279612114253.html" target="_top">WPF and Silverlight 学习笔记</a></li>
	  <li>·<a href="http://tech.ddvip.com/2009-04/1238861404113554.html" target="_top">单层人工神经网络应用示例</a></li>
	  <li>·<a href="http://tech.ddvip.com/2009-03/1238401534112866.html" target="_top">Linq To Sql进阶系列-从映射讲起</a></li>
		</ul>
			</div>
			<div class="dep_right_c">		
			<p><strong>专题推荐</strong></p>
		<ul>
	  <li> · <a href="http://tech.ddvip.com/zt/asp.net_video.html" target="_top">asp.net 视频教程</a></li>
	  <li> · <a href="http://tech.ddvip.com/zt/asp.net_database.html" target="_top">asp.net 数据库编程</a></li>
	  <li> · <a href="http://tech.ddvip.com/zt/asp.net_base.html" target="_top">asp.net 入门教程</a></li>
	  <li> · <a href="http://tech.ddvip.com/zt/asp.net_ado.net.html" target="_top">ado.net 教程</a></li>
	  <li> · <a href="http://tech.ddvip.com/zt/asp.net_talks.html" target="_top">asp.net 基础讲座</a></li>
	  <li> · <a href="http://tech.ddvip.com/zt/asp.net_ajax.html" target="_top">asp.net ajax 教程</a></li>
	  <li> · <a href="http://tech.ddvip.com/zt/asp.net_ajax_base.html" target="_top">asp.net ajax 入门系列</a></li>
	  <li> · <a href="http://tech.ddvip.com/zt/asp.net_controls_development.html" target="_top">asp.net 控件开发基础</a></li>
	  <li> · <a href="http://tech.ddvip.com/zt/asp.net_server_control.html" target="_top">asp.net 2.0 服务器控件</a></li>
	  <li> · <a href="http://tech.ddvip.com/zt/asp.net_2.0.html" target="_top">asp.net 2.0 教程</a></li>
	  <li> · <a href="http://tech.ddvip.com/zt/asp.net_controls.html" target="_top">asp.net 控件开发</a></li>
	  <li> · <a href="http://tech.ddvip.com/zt/asp.net_class.html" target="_top">asp.net 类</a></li>
	  <li> · <a href="http://tech.ddvip.com/zt/asp.net_paging.html" target="_top">asp.net 分页</a></li>
	  <li> · <a href="http://tech.ddvip.com/zt/asp.net_cache.html" target="_top">asp.net 页面缓存</a></li>
	  <li> · <a href="http://tech.ddvip.com/zt/asp.net_issue.html" target="_top">asp.net 常见问题解决</a></li>
	  <li> · <a href="http://tech.ddvip.com/zt/asp.net_master_pages.html" target="_top">asp.net 2.0 母版页</a></li>
	  <li> · <a href="http://tech.ddvip.com/zt/asp.net_sqlserver.html" target="_top">asp.net SQL Server</a></li>
	  <li> · <a href="http://tech.ddvip.com/zt/asp.net_mistake.html" target="_top">asp.net 错误</a></li>
	  <li> · <a href="http://tech.ddvip.com/zt/asp.net_matter.html" target="_top">asp.net 事件</a></li>
	  <li> · <a href="http://tech.ddvip.com/zt/asp.net_components.html" target="_top">asp.net 组件</a></li>
	  <li> · <a href="http://tech.ddvip.com/zt/asp.net_performance.html" target="_top">asp.net 性能</a></li>
	  <li> · <a href="http://tech.ddvip.com/zt/asp.net_upload.html" target="_top">asp.net 文件上传</a></li>
	  <li> · <a href="http://tech.ddvip.com/zt/asp.net.html" target="_top"><font color="#ff0000">更多asp.net专题……</font></a></li>
		</ul>
			</div>
		</div><!-- right -->
	</div><!-- content -->
	<div id="footer">
		<p><a href="http://www.ddvip.com/about.html">关于我们</a> | <a href="http://www.ddvip.com/contactus.html">联系我们</a> | <a href="http://www.ddvip.com/corp.html">版权申明</a> | <a href="http://www.ddvip.com/ad.html">广告服务</a> | <a href="http://www.ddvip.com/lawfirm.html">网站律师</a> | <a href="http://bbs.ddvip.com/">报告错误</a> | <a href="http://www.ddvip.com/disclaimer.html">免责条款</a></p>
		<p style="font-size: 9px;">Copyright © 2002 - 2009 ddvip All Rights Reserved</p>
		<p>豆豆网 版权所有</p>
	</div>
</div>	

<img src="stat.htm" border="0" height="0" width="0"><img src="stat_001.htm" border="0" height="0" width="0">


</body>
</html>
